<script setup>
import { useRouter } from 'vue-router'
const router = useRouter()
import { ArrowDown, HomeFilled } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'

//用户登录信息
const userStr = localStorage.getItem('user')
const user = JSON.parse(userStr)

//点击退出时清除本地信息
const handleCommand = async () => {
  // 退出操作
  await ElMessageBox.confirm('你确认要进行退出么', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  // 清除本地的数据 (token + user信息)
  //清除token
  localStorage.removeItem('token')
  // 清除用户信息
  router.push('/')
}

//修改密码
const getPassword = () => {
  router.push('/home/password')
}
//修改头像
const getAvatar = () => {
  router.push('/home/avatar')
}

//点击图标跳转到首页
const ComeHome = () => {
  router.push('/home/Course')
}
</script>
<template>
  <div id="head-tabar">
    <div style="float: left; margin-left: 1.8rem">
      <h3 style="color: white">
        {{ user.schoolName }}
      </h3>
    </div>
    <div style="float: right; margin-right: 100px">
      <el-icon @click="ComeHome()" class="my-icon"><HomeFilled /></el-icon>
      <el-dropdown>
        <span class="el-dropdown-link" style="color: white; margin-top: 20px; margin-left: 10px">
          {{ user.username }}
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item divided command="logout" @click="handleCommand"
              >安全退出</el-dropdown-item
            >
            <el-dropdown-item divided @click="getPassword">修改密码</el-dropdown-item>
            <el-dropdown-item divided @click="getAvatar">修改头像</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
      <el-avatar
        src="/src/assets/head1.jpeg"
        style="margin-left: 20px; top: 10px; float: left; position: absolute"
      ></el-avatar>
    </div>
  </div>
</template>
<style lang="scss" scoped>
#head-tabar {
  background: #68beb1;
  border-radius: 3px;
  width: 100%;
  height: 4.375rem;
  position: absolute;
}
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: white;
}
.my-icon {
  font-size: 1.5625rem;
  color: white;
  margin-top: 1.25rem;
}
</style>
